package hu.mapro.model.roo;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.addon.gwt.GwtOperations;
import org.springframework.roo.classpath.converters.JavaTypeConverter;
import org.springframework.roo.model.JavaType;
import org.springframework.roo.shell.CliAvailabilityIndicator;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;

/**
 * Sample of a command class. The command class is registered by the Roo shell following an
 * automatic classpath scan. You can provide simple user presentation-related logic in this
 * class. You can return any objects from each method, or use the logger directly if you'd
 * like to emit messages of different severity (and therefore different colours on 
 * non-Windows systems).
 * 
 * @since 1.1
 */
@Component // Use these Apache Felix annotations to register your commands class in the Roo container
@Service
public class MaproModelCommands implements CommandMarker { // All command types must implement the CommandMarker interface
    
    @Reference private MaproModelOperations operations;
    @Reference protected GwtOperations gwtOperations;
    
    @CliAvailabilityIndicator({ "mapro model setup"})
    public boolean isSetupCommandAvailable() {
        return operations.isSetupCommandAvailable();
    }
    
    @CliCommand(value = "mapro model setup", help = "Setup Mapro Model addon")
    public void setup() {
        operations.setup();
    }
    
    @CliAvailabilityIndicator({ "mapro model proxy"})
    public boolean isProxyCommandAvailable() {
        return operations.isProxyCommandAvailable();
    }
    
    @CliCommand(value = "mapro model proxy", help = "Create a class for the accessors of proxy objects in the project")
    public void proxyType(
            @CliOption(key = "class", mandatory = true, optionContext = JavaTypeConverter.PROJECT, help = "The java class to create") final JavaType type) {
    	operations.proxy(type);
    }
    
    
}